// 保留小数点后两位的过滤器，尾数四舍五入
export const  numFilter = (value) => {
  // 截取当前数据到小数点后两位
  let realVal = parseFloat(value).toFixed(2)
  return realVal
}
export const baseUrl =  'http://houlangguzi.com'
// export const baseUrl =  'https://test.lemashuju.com'
/*
  时间处理
    time：源时间戳
    type：要处理的格式 默认 xxxx年xx月xx日 xx:xx:xx
      /: xxxx/xx/xx xx:xx:xx
      .: xxxx.xx.xx xx:xx:xx
      -: xxxx-xx-xx xx:xx:xx
 */
export const normalTime = (time,type) => {
  if (time) {
    var date = new Date();
    date.setTime(time);
    console.log(date)
    var year = date.getFullYear();
    var month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) * 1 : date.getMonth() + 1;
    var day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
    var hours = date.getHours() < 10 ? '0' + date.getHours() : date.getHours();
    var minutes = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes();
    var seconds = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
    if(type == '-'){
      return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds
    }else if(type == '/'){
      return year + '/' + month + '/' + day + ' ' + hours + ':' + minutes + ':' + seconds;
    }else if(type == '+'){
      return  year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds;
    }else if(type == '.'){
      return year + '.' + month + '.' + day + ' ' + hours + ':' + minutes + ':' + seconds;
    }else{
      return year + '年' + month + '月' + day + '日' + ' ' + hours + ':' + minutes + ':' + seconds;
    }
  } else {
    return '-'
  }
}

export const normalDate = (time,type) => {
  if (time) {
    var date = new Date();
    date.setTime(time);
    var year = date.getFullYear();
    var month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) * 1 : date.getMonth() + 1;
    var day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
    if(type == '-'){
      return year + '-' + month + '-' + day
    }else if(type == '/'){
      return year + '/' + month + '/' + day;
    }else if(type == '+'){
      return month + '-' + day;
    }else if(type == '.'){
      return year + '.' + month + '.' + day;
    }else{
      return year + '年' + month + '月' + day + '日';
    }
  } else {
    return '-'
  }
}
export const toMoney = (num) => {
  num = num.toFixed(2);
  // num = parseFloat(num)
  num = num.toLocaleString();
  return num;//返回的是字符串23,245.12保留2位小数
}

export const getQueryString = (r, e) => {
 var t = new RegExp("(^|&|/?)" + e + "=([^&|/?]*)(&|/?|$)", "i"), o = r.substr(1).match(t);
   return null != o ? (console.log("r = " + o), console.log("r[2] = " + o[2]), o[2]) : null;
}

export const formatNumber = (value) => {
	let numerical=[];
	  let k = 10000,
	      sizes = ['', '万', '亿', '万亿'],
	      i;
	      if(value < k){
	        numerical=Number(value).toFixed(2)
	      }else{
	          i = Math.floor(Math.log(value) / Math.log(k)); 
	          numerical=((value / Math.pow(k, i))).toFixed(2)+sizes[i];
	      }
	      
	return numerical;
}
